package com.sys.ai.controller;

import com.sys.ai.domain.AiModel;
import com.sys.ai.fo.AiModelQueryFO;
import com.sys.ai.service.IAiModelService;
import com.sys.common.annotation.Log;
import com.sys.common.core.controller.BaseController;
import com.sys.common.core.domain.AjaxResult;
import com.sys.common.core.page.TableDataInfo;
import com.sys.common.enums.BusinessType;
import com.sys.common.utils.poi.ExcelUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 模型Controller
 *
 * @author LGY
 * @date 2025-05-08
 */
@Tag(name = "模型")
@RestController
@RequestMapping("/tool/aiModel")
public class AiModelController extends BaseController {
    @Autowired
    private IAiModelService aiModelService;

    /**
     * 查询模型列表
     */
    @PostMapping("/listAllEnable")
    @Operation(summary = "查询所有有效的模型")
    public AjaxResult listAll(@RequestBody AiModelQueryFO aiModelQueryFO) {
        List<AiModel> list = aiModelService.findAllEnableModel(aiModelQueryFO);
        return AjaxResult.success(list);
    }


    /**
     * 查询模型列表
     */
    @PostMapping("/list")
    @Operation(summary = "查询模型分页列表")
    public TableDataInfo list(@RequestBody AiModel aiModel) {
        startPage(aiModel);
        List<AiModel> list = aiModelService.selectAiModelList(aiModel);
        return getDataTable(list);
    }

    /**
     * 导出模型列表
     */
    @Log(title = "模型", businessType = BusinessType.EXPORT)
    @Operation(summary = "导出模型")
    @PostMapping("/export")
    public void export(HttpServletResponse response, AiModel aiModel) {
        List<AiModel> list = aiModelService.selectAiModelList(aiModel);
        ExcelUtil<AiModel> util = new ExcelUtil<AiModel>(AiModel.class);
        util.exportExcel(response, list, "模型数据");
    }

    /**
     * 获取模型详细信息
     */
    @Operation(summary = "查询模型详情")
    @GetMapping(value = "/detail/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(aiModelService.selectAiModelById(id));
    }

    /**
     * 新增模型
     */
    @Log(title = "模型", businessType = BusinessType.INSERT)
    @Operation(summary = "新增模型")
    @PostMapping("/save")
    public AjaxResult add(@RequestBody AiModel aiModel) {
        aiModelService.insertAiModel(aiModel);
        return success();
    }

    /**
     * 修改模型
     */
    @Log(title = "模型", businessType = BusinessType.UPDATE)
    @Operation(summary = "修改模型")
    @PutMapping("/update")
    public AjaxResult edit(@RequestBody AiModel aiModel) {
        aiModelService.updateAiModel(aiModel);
        return success();
    }

    /**
     * 删除模型
     */
    @Operation(summary = "删除模型")
    @Log(title = "模型", businessType = BusinessType.DELETE)
    @DeleteMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        aiModelService.deleteAiModelByIds(ids);
        return success();
    }
}
